package com.ChenYaRou.www.dao.impl;

import com.ChenYaRou.www.dao.StreetDao;
import com.ChenYaRou.www.po.Street;
import com.ChenYaRou.www.utils.GenerateSql;
import com.ChenYaRou.www.utils.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @ClassName StreetDaoImpl
 * @Description TODO
 * @Author 86183
 * @Date 2022/4/29 21:59
 * @Version 1.0
 **/
public class StreetDaoImpl implements StreetDao {
    /**
     * 查找街区集合
     * @param street 仅赋值条件的街区
     * @return 街区集合
     * @throws IllegalAccessException
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws InstantiationException
     */
    @Override
    public List<Street> select(Street street) throws IllegalAccessException, SQLException, NoSuchFieldException, InstantiationException {
        return JdbcUtil.getInstance().selectMore(GenerateSql.getInstance().select(street), Street.class);
    }

    /**
     * update street
     * @param newStreet street需要更新的值
     * @param  oldStreet old street
     * @return 成功与否
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int update(Street newStreet, Street oldStreet) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().update(newStreet,oldStreet));
    }

    /**
     * 插入street
     * @param street 新street
     * @return 更新条数
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int insert(Street street) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().insert(street));
    }
}
